//
//  HLEM3u8DownloadManager.h
//  DownloadM3U8Tool_Example
//
//  Created by hle1879 on 2020/8/28.
//  Copyright © 2020 134344. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AFNetworking/AFNetworking.h>
#import "HLEM3U8DownloadTask.h"
#import "HLEM3U8WorkFlow.h"
#import "HLEConfig.h"

NS_ASSUME_NONNULL_BEGIN

@interface HLEM3u8DownloadManager : NSObject

@property(class, readonly, strong) HLEM3u8DownloadManager *standardUserDefaults;
@property(nonatomic,strong,readonly)AFHTTPSessionManager *manager;

///初始化下载配置
///@param config 下载的配置
- (void)initializeSDKWithConfig:(HLEConfig  * _Nullable )config;

///创建下载任务
/// @param taskID taskID
/// @param downloadUrl 下载的URL
/// @param fileSavePath 保存文件的路径(ps:Caches/HLEDownloadM3u8/17512098093/1598605466)
/// @return complete 完成的回调(state: YES,NO。任务创建成功，任务创建失败)
- (HLEM3U8DownloadTask *)creatTaskById:(NSInteger)taskID
                           downloadUrl:(NSString *)downloadUrl
                          fileSavePath:(NSString *)fileSavePath
                               success:(nullable void (^)(HLEM3U8DownloadTask *task))success
                               failure:(nullable void (^)(HLEM3U8DownloadTask *task,NSError *error))failure;


///获取所有的下载记录
- (NSArray <HLEM3U8DownloadTask *>*)getAllM3u8DownloadTask;

///开始任务
/// @param task 任务
/// @param progress 进度
/// @param speed byte/s
/// @param success 成功
/// @param failure 失败
- (BOOL)resumeTask:(HLEM3U8DownloadTask *)task
          progress:(void (^)(HLEM3U8DownloadTask *task,NSProgress *progress, NSInteger allSize))progress
             speed:(void (^)(HLEM3U8DownloadTask *task,NSInteger speed))speed
           success:(nullable void (^)(HLEM3U8DownloadTask *task))success
           failure:(nullable void (^)(HLEM3U8DownloadTask *task,NSError *error))failure;


///恢复任务
/// @param taskID 任务
/// @param progress 进度
/// @param speed byte/s
/// @param success 成功
/// @param failure 失败
- (BOOL)resumeTaskBytaskID:(NSInteger)taskID
                  progress:(void (^)(HLEM3U8DownloadTask *task,NSProgress *progress, NSInteger allSize))progress
                     speed:(void (^)(HLEM3U8DownloadTask *task,NSInteger speed))speed
                   success:(nullable void (^)(HLEM3U8DownloadTask *task))success
                   failure:(nullable void (^)(HLEM3U8DownloadTask *task,NSError *error))failure;

///暂停任务
/// @param task 任务
- (BOOL)pauseTask:(HLEM3U8DownloadTask *)task;

///暂停任务
/// @param taskID 任务ID
- (BOOL)pauseTaskBytaskID:(NSInteger)taskID;

///取消任务
/// @param task 任务
- (BOOL)cancelTask:(HLEM3U8DownloadTask *)task;

///取消任务
/// @param taskID 任务ID
- (BOOL)cancelTaskBytaskID:(NSInteger)taskID;

///合并ts文件转换成mp4
/// @param taskID 任务ID
/// @param tsfilepath 合并成ts的文件路径
/// @param mp4FilePath 合并成mp4的文件路径
/// @param success 合并成功
/// @param failure 合并失败
- (void)combineMP4ByTaskID:(NSInteger)taskID
                tsFilePath:(NSString *)tsfilepath
               mp4FilePath:(NSString *)mp4FilePath
                   success:(nullable void (^)(HLEM3U8DownloadTask *task))success
                   failure:(nullable void (^)(HLEM3U8DownloadTask *task,NSError *error))failure;

///App切换到后台
- (void)applicationDidEnterBackground:(UIApplication *)application;

///Appq切换到前台
- (void)applicationWillEnterForeground:(UIApplication *)application;

@end

NS_ASSUME_NONNULL_END
